<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单详情')" />
    <object  id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0/>
    </object>
    <script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script>
<!--    <script src="http://192.168.126.1/CLodopfuncs.js"></script>
    <script src="http://localhost:8000/CLodopfuncs.js? priority=1"></script>-->
    <script type="text/javascript" src="/js/LodopFuncs.js"></script>
    <script type="text/javascript" src="/js/printSmall.js"></script>

   <!-- <script type="text/javascript" >
        var LODOP; //声明为全局变量
        function p(idorderHead) {
            console.log(idorderHead)
            if (/(Android)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else {
                console.log("i`am computer")
            }
            var url =  prefix + '/printSmall/'+idorderHead;
            $.getJSON(url,function (json) {
                if(json.code!=0){
                    $.modal.msgWarning(json.msg)
                    return;
                }

                var map = json.data;
                let order = map.order;
                let date = map.date;
                let itemList = map.itemList;
                console.log(order)
                setTimeout(function () {
                    //设置为小票打印机
                    LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","NPI24D743 (HP LaserJet Pro MFP M226dw)");
                    //LODOP.SET_PRINTER_INDEX(2);
                    LODOP.PRINT_INIT("打印任务名");               //首先一个初始化语句
                    LODOP.SET_PRINT_STYLEA(2,"FontSize",8);
                    LODOP.SET_PRINT_STYLEA(2,"FontName","宋体");
                    //LODOP.ADD_PRINT_TEXT(100, 50, 100, 20, "文本内容一");//然后多个ADD语句及SET语句
                    LODOP.ADD_PRINT_TEXT(53,97,100,20,"***************");
                    LODOP.ADD_PRINT_TEXT(77,97,100,20,"***************");
                    LODOP.ADD_PRINT_TEXT(65,97,100,20,"*    新订单   *");
                    LODOP.ADD_PRINT_TEXT(120,14,100,20,"订单号: "+order.no);
                    LODOP.ADD_PRINT_TEXT(215,14,257,20,"- - - - - - - - - - - - - - - - - - - - - ");
                    LODOP.ADD_PRINT_TEXT(200,14,235,24,"提货日期: "+date);
                    LODOP.ADD_PRINT_TEXT(183,14,145,23,"地址: "+order.city+" "+order.town);
                    LODOP.ADD_PRINT_TEXT(147,14,145,23,"电话号码: "+order.phone);
                    LODOP.ADD_PRINT_TEXT(133,14,100,20,"客户: "+order.clientName);
                    LODOP.ADD_PRINT_TEXT(230,14,45,25,"种类");
                    LODOP.ADD_PRINT_TEXT(230,211,33,25,"数量");
                    LODOP.ADD_PRINT_TEXT(230,240,44,25,"价钱");
                    $(itemList).each(function(index,item){
                        LODOP.ADD_PRINT_TEXT(245+index*20,14,210,25,item.nameProduct);
                        LODOP.ADD_PRINT_TEXT(245+index*20,211,50,25,item.count);
                        LODOP.ADD_PRINT_TEXT(245+index*20,240,50,25,item.priceProduct);
                    })
                    LODOP.ADD_PRINT_TEXT(295,14,100,25,"备注: "+order.desc);
                    LODOP.ADD_PRINT_TEXT(280,14,257,20,"- - - - - - - - - - - - - - - - - - - - - ");
                    LODOP.PREVIEW();
                    //LODOP.PRINT();                               //最后一个打印(或预览、维护、设计)语句
                    //设置为默认打印机
                    LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","HP LaserJet Pro MFP M225-M226 PCL 6");
                }, 1000)
            })
        }
    </script>-->
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号码：</label>
                                <input type="text" name="idorderHead"/>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <input type="text" name="clientName"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="phoneOne"/>
                            </li>
                            <li>
                                <label>紧急电话：</label>
                                <input type="text" name="phoneTwo"/>
                            </li>
                            <li>
                                <label>下单日期：</label>
                                <input  type="text" class="time-input" placeholder="开始时间" name="addStime"/>-<input  type="text" class="time-input" placeholder="结束时间" name="addEtime"/>
                            </li>
                            <li>
                                <label>交货日期：</label>
                                <input type="text" class="time-input" placeholder="开始时间" name="appStime"/>-<input type="text" class="time-input" placeholder="结束时间" name="appEtime"/>
                            </li>
                            <li>
                                订单状态：<select name="stateOrderHead" th:with="type=${@dict.getType('sys_order_state')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                <div class="form-group" >
                                    <label>所在城市：</label>
                                    <select id="shi"  onblur="zhenUpdate()" >
                                        <option value="" >所有</option>
                                    </select>
                                    <select id="zhen"  name="regionClient" >
                                        <option value="">所有</option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:orderhead:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:orderhead:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="removeAll()" shiro:hasPermission="system:orderhead:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:orderhead:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.printAll()" shiro:hasPermission="system:orderhead:remove">
                    <i class="fa fa-remove"></i> 批量打印
                </a>
                <a id="printerOrdersId" class="btn btn-warning" onclick="printerOrders()"  shiro:hasPermission="system:orderhead:export">
                    <i class="fa fa-download"></i> 打印今日全部订单
                </a>
                <a class="btn btn-danger" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:orderhead:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:orderhead:remove')}]];
        var listFlag = [[${@permission.hasPermi('system:orderhead:list')}]];
        var types = [[${@dict.getType('sys_order_state')}]];
        var prefix = ctx + "system/orderhead";
        var orderTable = ctx + "system/ordertable";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "【订单信息】",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'idorderHead',
                    title: '订单号码',
                },
                {
                    field: 'cName',
                    title: '客户名称'
                },
                {
                    field: 'phoneone',
                    title: '联系电话'
                },
                {
                    field: 'phonetwo',
                    title: '紧急电话'
                },
                {
                    field: 'rName',
                    title: '订单地址'
                },
                {
                    field: 'addTime',
                    title: '下单时间'
                },
                {
                    field: 'appTime',
                    title: '交货日期'
                },
                    {
                        field: 'allMoney',
                        title: '订单总价'
                    },
                {
                    field: 'uName',
                    title: '下单人'
                },
                {
                    field: 'state',
                    title: '订单状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field: 'comment',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                       /* actions.push('<a   class="btn btn-info btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="p(\'' + row.idorderHead + '\')"><i class="fa fa-list-ul"></i>打印小票</a> ');*/
                        actions.push('<a   class="btn btn-info btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="print(\'' + row.idorderHead + '\')"><i class="fa fa-list-ul"></i>打印订单</a> ');
                        /*actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.idorderHead + '\')"><i class="fa fa-list-ul"></i>添加商品</a> ');*/
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.idorderHead + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.idorderHead + '\')"><i class="fa fa-remove"></i>取消</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        $(function(){
            let attribute = window.frameElement.getAttribute('data-id');
            let boolean = attribute.indexOf("/system/orderhead/getDaysOrder");
            console.log("boolean"+boolean);
            if(boolean){
                $("#printerOrdersId").hide();
            }else{
                addCookie("date1",attribute);
            }
        })
        //写Cookie
        function addCookie(objName, objValue, objHours) {
            var str = objName + "=" + escape(objValue); //编码
            if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失
                var date = new Date();
                var ms = objHours * 3600 * 1000;
                date.setTime(date.getTime() + ms);
                str += "; expires=" + date.toGMTString();
            }
            document.cookie = str;
        }

        // 提交数据
         function removeSubmit(url, type, dataType, data, callback) {
            var config = {
                url: url,
                type: type,
                dataType: dataType,
                data: data,
                success: function(result) {
                    if (typeof callback == "function") {
                        if (/(Android)/i.test(navigator.userAgent)) {
                            setTimeout(function(){$.operate.successCallback(result);},5000);
                            return ;
                        } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                            setTimeout(function(){$.operate.successCallback(result);},5000);
                            return ;
                        }
                        callback(result.data);
                        let attribute = window.frameElement.getAttribute('data-id');
                        let boolean = attribute.indexOf("/system/orderhead/getDaysOrder");
                        if(boolean){
                            /*setTimeout(function(){$.modal.openTab("订单明细","/system/orderhead/0",true); }, 1500);*/
                            setTimeout(function(){$.operate.successCallback(result);},2000);
                        }else{
                            let jQueryElement = $("tbody").children()[0];
                            let jQueryElement1 = $(jQueryElement).children()[5];
                            let text = $(jQueryElement1).text();
                            setTimeout(function(){$.modal.openTab("每日订单详情","/system/orderhead/getDaysOrder/"+text,true);},2000)
                        }
                    }
                    $.modal.msgSuccess(result.msg);

                }
            };
            $.ajax(config)
        }
        function channelP(idOrids){
           let arr =  idOrids.split(',');
           if(arr.length > 1){
               $(arr).each(function(index,item){
                   channel(item)
               })
           }else{
               channel(idOrids)
           }
        }
        // 删除信息
        function remove(id) {
            table.set();
            $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗？", function() {
                var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
                if(table.options.type == table_type.bootstrapTreeTable) {
                    $.operate.get(url);
                } else {
                    var data = { "ids": id };
                    removeSubmit(url, "post", "json", data,channelP);
                }
            });
        }
        // 批量删除信息
        function removeAll() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
                var url = table.options.removeUrl;
                var data = { "ids": rows.join() };
                removeSubmit(url, "post", "json", data,channelP);
            });
        }
        function printerOrders(){
            let jQueryElement2 = $("tbody").children()[0];
            let jQueryElement3 = $(jQueryElement2).children()[5];
            let text2 = $(jQueryElement3).text();
            $.modal.confirm("确认要打印" + text2 + "的所有数据吗? 请注意没有添加商品的订单默认不打印", function() {
                let jQueryElement = $("tbody").children()[0];
                let jQueryElement1 = $(jQueryElement).children()[5];
                let text = $(jQueryElement1).text();
                let jQueryElementLast = $("tbody").children()[0];
                let jQueryElement2 = $(jQueryElement).children()[5];
                let text1 = $(jQueryElement1).text();
                /*以下判断暂时没用,最后的保险 ,当列表第一条和最后一条日期不一致 不允许打印 */
                if (text === text1) {
                    $.getJSON("/system/orderhead/getDaysOrderPrintList/" + text, function (json) {
                        console.log(json)
                        $(json).each(function (index, item) {
                            if (/(Android)/i.test(navigator.userAgent)) {
                                alert("手机端不允许打印!")
                                return;
                            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                                alert("手机端不允许打印!")
                                return;
                            } else {
                                console.log("i`am computer")
                            }
                            var url = prefix + '/print/' + item;
                            $.modal.openTab("打印订单", url);
                        })
                        setTimeout(function () {
                            $.modal.openTab("每日订单详情", "/system/orderhead/getDaysOrder/" + text, false);
                        }, 200);
                    })
                } else {
                    $.modal.msgWarning("未避免打印内容较多 本页面仅可使用批量打印功能!");
                }
            })
        }
        /*订单-详细*/
        function detail(idorderHead) {
            var url = orderTable + '/read/' + idorderHead;
            //var url = orderTable ;
            $.modal.openTab("订单详情", url);
        }

        function print(idorderHead){
            if (/(Android)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else {
                console.log("i`am computer")
            }
           var url =  prefix + '/print/'+idorderHead;
           $.modal.openTab("打印订单",url);
            let attribute = window.frameElement.getAttribute('data-id');
            let boolean = attribute.indexOf("/system/orderhead/getDaysOrder");
            if(boolean){
                setTimeout(function(){$.modal.openTab("订单明细","/system/orderhead/0",false); }, 200);
            }else{
                let jQueryElement = $("tbody").children()[0];
                let jQueryElement1 = $(jQueryElement).children()[5];
                let text = $(jQueryElement1).text();
                setTimeout(function(){$.modal.openTab("每日订单详情","/system/orderhead/getDaysOrder/"+text,false); }, 200);
            }

           //$.modal.reload();
        }
        function printSmall(idorderHead){
            if (/(Android)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                alert("手机端不允许打印!")
                return ;
            } else {
                console.log("i`am computer")
            }
            var url =  prefix + '/printSmall/'+idorderHead;
            $.modal.openTab("打印订单",url);
        }

        $(function(){
            $("#shi").html("");
            let url = "/system/region/listById";
            let param = {"parentId":27425};
            $.getJSON(url,param,function(json){
                let rows = json.rows;
                $(rows).each(function(i,item){
                    let html = '';
                    html += '<option value='+item.idRegion+'>'+item.nameRegion+'</option>';
                    $("#shi").append(html);
                })
            })
        })
        function zhenUpdate(){
            $("#zhen").html("");
            let url = "/system/region/listById";
            let parentId = $("#shi").val();
            let param = {"parentId":parentId};
            $.getJSON(url,param,function(json){
                let rows = json.rows;
                $(rows).each(function(i,item){
                    let html = '';
                    html += '<option value='+item.idRegion+'>'+item.nameRegion+'</option>';
                    $("#zhen").append(html);
                })
            })
        }

        /** 关闭选项卡 */
        var closeItem = function(dataId){
            var topWindow = $(window.parent.document);
            if($.common.isNotEmpty(dataId)){
                window.parent.$.modal.closeLoading();
                // 根据dataId关闭指定选项卡
                $('.menuTab[data-id="' + dataId + '"]', topWindow).remove();
                // 移除相应tab对应的内容区
                $('.mainContent .RuoYi_iframe[data-id="' + dataId + '"]', topWindow).remove();
                return;
            }
            var panelUrl = window.frameElement.getAttribute('data-panel');
            $('.page-tabs-content .active i', topWindow).click();
            if($.common.isNotEmpty(panelUrl)){
                $('.menuTab[data-id="' + panelUrl + '"]', topWindow).addClass('active').siblings('.menuTab').removeClass('active');
                $('.mainContent .RuoYi_iframe', topWindow).each(function() {
                    if ($(this).data('id') == panelUrl) {
                        $(this).show().siblings('.RuoYi_iframe').hide();
                        return false;
                    }
                });
            }
        }
    </script>
</body>
</html>